/************************************************************************/
/* @file            gxMutex.h                                           */
/* @brief           Mutex                                               */
/* @version         2013.11.14 johnxguo created                         */
/************************************************************************/

#ifndef __GX_MUTEX_H_INCLUDED__
#define __GX_MUTEX_H_INCLUDED__

#include "gxPlatform.h"

#ifdef _GX_WINDOWS_
#include <windows.h>
#define MutexTypeName      CRITICAL_SECTION
#define MutexInit(x)       InitializeCriticalSection(x)
#define MutexSetP(x)       EnterCriticalSection(x)
#define MutexSetV(x)       LeaveCriticalSection(x)
#else
#include <sys/time.h>
#include <pthread.h>
#define MutexTypeName      pthread_mutex_t
#define MutexInit(x)       pthread_mutex_init(x)
#define MutexSetP(x)       pthread_mutex_lock(x)
#define MutexSetV(x)       pthread_mutex_unlock(x)
#endif

namespace gx
{
namespace base
{
class CGxMutex
{
public:

    CGxMutex()
    {
        MutexInit(&m_signal);
    }
    ~CGxMutex(){}

    inline void P()
    {
        MutexSetP(&m_signal);
    };

    inline void V()
    {
        MutexSetV(&m_signal);
    };

private:
    MutexTypeName m_signal;
};

}//end namespace base
}//end namespace gx

#endif